package com.wk.springframework.bean;

import com.wk.springframework.beans.factory.BeanClassLoaderAware;
import com.wk.springframework.beans.factory.BeanNameAware;
import com.wk.springframework.beans.factory.DisposableBean;
import com.wk.springframework.beans.factory.InitializingBean;
import com.wk.springframework.context.ApplicationContext;
import com.wk.springframework.context.ApplicationContextAware;

/**
 * 作者：DerekYRC https://github.com/DerekYRC/mini-spring
 */
public class UserService implements InitializingBean, DisposableBean, BeanClassLoaderAware, BeanNameAware, ApplicationContextAware {

    private String id;

    private UserDao userDao;

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    private String company;
    private String location;

    public String queryUserInfo() {
        return userDao.queryUserName(id) + company + location;
    }

    public String getId() {
        return id;
    }

    public void setId(String uId) {
        this.id = uId;
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行：UserService.afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("执行：UserService.destroy");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("UserService setBeanClassLoader" + classLoader);
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("UserService setBeanName" + name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        Object userDao1 = applicationContext.getBean("userDao");
        System.out.println("UserService setApplicationContext" + applicationContext + "get userDao:" + userDao1);
    }
}
